/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_te_init_packet.c    mm                           */
/*  NOTE      =                                                    */
/*  DATE      = 2017/02/24 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>

#include "frcomm.h"
#include "frmem.h"

#include <tongeasy/config.h>
#include <tongeasy/te_core.h>
#include <tongeasy/te_packet.h>
#include <tongeasy/te_comm.h>

extern void __te_destroy_packet(L7_te_packet **pp_st_te_packet);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    L7_te_packet *p_st_te_packet = NULL;
    p_st_te_packet = (L7_te_packet *) frmalloc(sizeof(L7_te_packet));
    CU_ASSERT_PTR_NOT_NULL(p_st_te_packet);
    memset(p_st_te_packet, 0x00, sizeof(L7_te_packet));

    CU_ASSERT_EQUAL(te_init_packet(p_st_te_packet), FR_SUCC);

    CU_ASSERT_EQUAL(p_st_te_packet->fragment_state, APM_TE_FRAGMENT_INIT);
    CU_ASSERT_PTR_NOT_NULL(p_st_te_packet->p_st_packet);
    CU_ASSERT_EQUAL(p_st_te_packet->ui_len_to_read, 0);
    CU_ASSERT_EQUAL(p_st_te_packet->i_is_req, APM_TE_FLAG_UNSET);

    __te_destroy_packet(&p_st_te_packet);
    CU_ASSERT_PTR_NULL(p_st_te_packet);
}

int add_suite_te_init_packet(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" te_init_packet()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
